<template>
  <div class="head-container">
    <content-block label="机关养老信息表">
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" height="550" border :header-cell-style="{background:'#f5f7fa', color:'#777'}" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="aac002" label="证件号" width="220px" align="center" header-align="center" fixed="left" />
        <el-table-column prop="aac003" label="姓名" width="220px" align="center" header-align="center" fixed="left" />
        <el-table-column prop="aac001" label="个人编号" width="180px" align="center" header-align="center" />
        <el-table-column prop="aae270" label="联系函编号" width="220px" align="center" header-align="center" />
        <el-table-column prop="aab300" label="转出单位名称" width="220px" align="center" header-align="center" />
        <el-table-column prop="aie074" label="转移基金总额" width="220px" align="center" header-align="center" />
        <el-table-column prop="aae11" label="经办人" width="220px" align="center" header-align="center" />
        <el-table-column prop="aae036" label="经办时间" width="220px" :formatter="formatDate" align="center" header-align="center" />
        <el-table-column prop="aae013" label="备注" header-align="center" />
        <el-table-column
          fixed="right"
          label="打印"
          align="center"
          header-align="center"
          width="200"
        >
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-printer" size="mini" @click="print(scope.row)" />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </content-block>
  </div>
</template>

<script>
import CRUD, { presenter, header, form, crud } from '@crud/crud'

import pagination from '@crud/Pagination'
import ContentBlock from '@/components/labers/contentBlock.vue'

const defaultForm = { aaz153: null, aaa032: null, aaa030: null, aaa031: null, aae013: null, aae011: null, aae036: null, aae041: null, aae042: null, aab359: null }
export default {
  name: 'Ic66xxb',
  components: { ContentBlock, pagination },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['aaa030'],
  cruds() {
    return CRUD({
      title: '利率',
      url: 'api/transferPrint/queryTransferIc66',
      idField: 'aaz341',
      sort: 'aae036,desc',
      crudMethod: {
        // 确保这里包含查询方法
        list: this.getList
      }
    })
  },
  props: {
    // 接收主组件传递的查询参数
    baseParams: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      // 可以添加需要的data
    }
  },
  created() {
    this.crud.toQuery()
  },
  methods: {
    // 查询方法
    getList() {
      return new Promise((resolve, reject) => {
        this.crud.params = {
          aac002: this.baseParams.aac002,
          aac003: this.baseParams.aac003,
          aae270: this.baseParams.aae270
        }
        this.crud.refresh()
          .then(res => {
            resolve(res)
          })
          .catch(err => {
            reject(err)
          })
      })
    },

    // 个人账户打印
    print(row) {
      window.open('http://localhost:8085/jmreport/view/1114795132409389056?token=123456&tenantId=3&aaz341=' + row.aaz341, '_blank')
    },

    // 日期格式转换
    formatDate(row, column, cellValue) {
      if (cellValue !== null && cellValue !== undefined) {
        const date = new Date(cellValue)
        const year = date.getFullYear()
        const month = (date.getMonth() + 1).toString().padStart(2, '0')
        return `${year}-${month}`
      } else {
        return '--'
      }
    },

    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container2 {
  padding: 10px 14px;
  background: #f0f2f58c;

  .head-container {
    background-color: #fff;
    height: 98%;
    padding: 10px;
  }

  .el-table{
    height: calc(100vh - 360px);
    overflow: auto;
  }
}
</style>
